<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Event_model extends CI_Model {

	function __construct() {
		parent::__construct();
		
	}

	/**
	 * 이벤트 정보 가져오기
	 */
	function get_event($event_id) {
		log_message('debug',"#### Event_model::get_event($event_id)");
		
		$this->db->where('event_id', $event_id);
		$query = $this->db->get('tb_event') or $this->logsql->log_sql('error');
		$result = $query->row_array();
		
		$this->logsql->log_sql();
		$this->logsql->log_result($result);

		return $result;
	}
	
	/**
	 * 이미 참여했는지 확인
	 */
	function is_already_entry($event_id, $user_id) {
		log_message('debug',"#### Event_model::is_already_entry($event_id, $user_id)");
		
		$this->db->where('event_id', $event_id);
		$this->db->where('user_id' , $user_id);
		$this->db->from('tb_event_entry');
		$result = $this->db->count_all_results();

		$this->logsql->log_sql();
		$this->logsql->log_result($result);

		if ($result > 0) {
			return TRUE;
		}
        return FALSE;
	}

	/**
	 * 이벤트 참여 처리
	 */
	function insert_event_entry($event_id, $user_id, $message) {
		log_message('debug',"#### Event_model::insert_event_entry($event_id, $user_id, $message)");
		
		$this->db->set('event_id' , $event_id);
		$this->db->set('user_id'  , $user_id);
		$this->db->set('message'  , $message);
		$this->db->set('create_dt', 'now()', FALSE);
		$this->db->insert('tb_event_entry') or $this->logsql->log_sql('error');
		
		$this->logsql->log_sql();
	}
}

/* End of file event_model.php */
/* Location: ./application/models/event/event_model.php */